package com.siqi.hr.system.custom.entity;

import com.siqi.hr.system.common.sql.Parsable;
import com.siqi.hr.system.common.sql.STable;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.util.Assert;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

/**
 * 注册实体对象
 * @author    xiaogq
 * Created by xiaogoingqin on 2016/7/23.
 */
public class EntityRecord implements Serializable,Parsable<STable> {

    public STable parse() {
        Assert.notNull(tableCode, "表名不能为空");
        return new STable("t_"+tableCode);
    }

    /**
     *  表对应的编码
     */
    private int tableCode;

    /**
     *  表名(英文)
     */
    private String name;

    /**
     *  中文
     */
    private String inchinese;

    /**
     *  实体编辑页布局，当实体对象有类型时，为NULL
     */
    private String layoutEdit;

    /**
     * 实体查看页布局
     */
    private String layoutShow;

    /**
     * 实体所属模块
     */
    private String belongMudule;

    /**
     * 实体是否是受权限控制实体(0:否，1：是默认值为1)
     */
    private Boolean permission;

    /**
     * 实体是否可以自定义属性(也就是是否可以添加自定义字段)(0:否，1：可以默认值为1) 注：这个字段与之前crm取值刚好相反，相关代码需要调整
     */
    private Boolean defineField;

    /**
     * 实体是否系统实体(0:否，1：是默认值为0)
     */
    private Boolean systemEntity;

    /**
     * 实体是否有类型(0:否，1：是默认值为0)
     */
    private Boolean defineType;

    /**
     * 实体是否可以定义审批流(0:否，1：是默认值为0)
     */
    private Boolean defineApproval;

    /**
     * 实体是否可以定义业务逻辑(0:否，1：是默认值为0)
     */
    private Boolean defineLogic;

    /**
     * 实体是否允许定义工作流(0:否，1：是默认值为0)
     */
    private Boolean defineStageManager;

    /**
     * 实体是否可以被引用(0:否，1：是默认值为0)
     */
    private Boolean canQuote;

    /**
     * 实体是否可以定义消息(0:否，1：是默认值为0)
     */
    private Boolean defineMessage;

    /**
     * 实体是否在实体列表中显示（0：不显示，1：显示默认为1）注：这个字段与之前crm取值刚好相反，相关代码需要调整
     */
    private Boolean nodisplay;

    /**
     * 实体是否有明细实体(0:否，1：是默认值为0)
     */
    private Boolean defineSet;

    /**
     * 实体是否是明细实体(0:否，1：是默认值为0)
     */
    private Boolean setElement;

    /**
     * 实体是否使用回收站(0:否，1：是默认值为0)
     */
    private Boolean useRecyclebin;

    /**
     * 实体创建时间
     */
    private Date createDate;

    /**
     *  更新时间
     */
    private Date updateDate;

    /**
     * 排序
     */
    private int position;

    public EntityRecord() {
    }

    public EntityRecord(Integer tableCode) {
        this.tableCode = tableCode;
    }

    /**
     * author：xiaogq
     * @param tableCode
     * @param inchinese
     */
    public EntityRecord(Integer tableCode, String inchinese){
        this.tableCode = tableCode;
        this.inchinese = inchinese;
    }

    public int getTableCode() {
        return tableCode;
    }

    public void setTableCode(int tableCode) {
        this.tableCode = tableCode;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getInchinese() {
        return inchinese;
    }

    public void setInchinese(String inchinese) {
        this.inchinese = inchinese;
    }

    public String getLayoutEdit() {
        return layoutEdit;
    }

    public void setLayoutEdit(String layoutEdit) {
        this.layoutEdit = layoutEdit;
    }

    public String getLayoutShow() {
        return layoutShow;
    }

    public void setLayoutShow(String layoutShow) {
        this.layoutShow = layoutShow;
    }

    public String getBelongMudule() {
        return belongMudule;
    }

    public void setBelongMudule(String belongMudule) {
        this.belongMudule = belongMudule;
    }

    public Boolean getPermission() {
        return permission;
    }

    public void setPermission(Boolean permission) {
        this.permission = permission;
    }

    public Boolean getDefineField() {
        return defineField;
    }

    public void setDefineField(Boolean defineField) {
        this.defineField = defineField;
    }

    public Boolean getSystemEntity() {
        return systemEntity;
    }

    public void setSystemEntity(Boolean systemEntity) {
        this.systemEntity = systemEntity;
    }

    public Boolean getDefineType() {
        return defineType;
    }

    public void setDefineType(Boolean defineType) {
        this.defineType = defineType;
    }

    public Boolean getDefineApproval() {
        return defineApproval;
    }

    public void setDefineApproval(Boolean defineApproval) {
        this.defineApproval = defineApproval;
    }

    public Boolean getDefineLogic() {
        return defineLogic;
    }

    public void setDefineLogic(Boolean defineLogic) {
        this.defineLogic = defineLogic;
    }

    public Boolean getDefineStageManager() {
        return defineStageManager;
    }

    public void setDefineStageManager(Boolean defineStageManager) {
        this.defineStageManager = defineStageManager;
    }

    public Boolean getCanQuote() {
        return canQuote;
    }

    public void setCanQuote(Boolean canQuote) {
        this.canQuote = canQuote;
    }

    public Boolean getDefineMessage() {
        return defineMessage;
    }

    public void setDefineMessage(Boolean defineMessage) {
        this.defineMessage = defineMessage;
    }

    public Boolean getNodisplay() {
        return nodisplay;
    }

    public void setNodisplay(Boolean nodisplay) {
        this.nodisplay = nodisplay;
    }

    public Boolean getDefineSet() {
        return defineSet;
    }

    public void setDefineSet(Boolean defineSet) {
        this.defineSet = defineSet;
    }

    public Boolean getSetElement() {
        return setElement;
    }

    public void setSetElement(Boolean setElement) {
        this.setElement = setElement;
    }

    public Boolean getUseRecyclebin() {
        return useRecyclebin;
    }

    public void setUseRecyclebin(Boolean useRecyclebin) {
        this.useRecyclebin = useRecyclebin;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    /**
     * 查询实体id与名称字段信息
     */
    public static class mainEntityRecord extends EntityRecord implements RowMapper<EntityRecord> {
        public synchronized EntityRecord mapRow(ResultSet rs, int index) throws SQLException {
            EntityRecord entity = new EntityRecord();
            entity.setTableCode(rs.getInt("table_code"));
            entity.setName(rs.getString("name"));
            entity.setInchinese(rs.getString("inchinese"));
            return entity;
        }
    }

    /**
     * 查询实体所有信息
     */
    public static class FullEntityRecord extends EntityRecord implements RowMapper<EntityRecord> {
        public synchronized EntityRecord mapRow(ResultSet rs, int index) throws SQLException {
            EntityRecord entity = new EntityRecord();
            entity.setTableCode(rs.getInt("table_code"));
            entity.setName(rs.getString("name"));
            entity.setInchinese(rs.getString("inchinese"));
            entity.setCreateDate(rs.getDate("create_date"));
            entity.setUpdateDate(rs.getDate("update_date"));
            entity.setLayoutEdit(rs.getString("layout_edit"));
            entity.setLayoutShow(rs.getString("layout_show"));
            entity.setBelongMudule(rs.getString("belong_mudule"));
            entity.setPermission(rs.getBoolean("permission"));
            entity.setDefineField(rs.getBoolean("define_field"));
            entity.setSystemEntity(rs.getBoolean("system_entity"));
            entity.setDefineType(rs.getBoolean("define_type"));
            entity.setDefineApproval(rs.getBoolean("define_approval"));
            entity.setDefineLogic(rs.getBoolean("define_logic"));
            entity.setDefineStageManager(rs.getBoolean("define_stage_manager"));
            entity.setCanQuote(rs.getBoolean("can_quote"));
            entity.setDefineMessage(rs.getBoolean("define_message"));
            entity.setNodisplay(rs.getBoolean("nodisplay"));
            entity.setDefineSet(rs.getBoolean("define_set"));
            entity.setSetElement(rs.getBoolean("set_element"));
            entity.setUseRecyclebin(rs.getBoolean("use_recyclebin"));
            entity.setPosition(rs.getInt("position"));
            return entity;
        }
    }
}
